// 添加边，是的，删掉一条边，依然可以联通
#include <bits/stdc++.h>
using namespace std;

vector<pair<int, int>> G[10000];
int degree[10000];

int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    G[u].push_back({v, w});
    G[v].push_back({u, w});
    degree[u]++;
    degree[v]++;
  }

  // 计算叶子节点数
  int leaves = 0;
  for (int i = 1; i <= n; i++) {
    if (degree[i] == 1) leaves++;
  }

  // 计算需要添加的最少边数
  int min_edges = (leaves + 1) / 2;
  cout << min_edges << endl;

  return 0;
}